<template>
  <div>
    <header class="site-header jumbotron">
      <div class="container">
        <div class="row">
          <div class="col-xs-12">
            <h1>请发表你对Vue的评论</h1>
          </div>
        </div>
      </div>
    </header>

    <div class="container">
      <Add :addComments="addComments"/>
<!--      组件间通信，通过属性传递，最好同名-->
      <List :comments="comments" :deleteComment="deleteComment"/>
    </div>
  </div>
</template>

<script>
  import Add from './components/Add'
  import List from './components/List'
  import confirm_report from './utils/confirm_report'
  import naranja from './utils/naranja'

export default {
  name: 'App',
  data(){
    return{
      comments:[ /*数据在哪个组件，更新数据的行为就应该在哪个组件*/
        {name:'BOB',content:'Vue 还不错'},
        {name:'Cat',content:'Vue So Easy'},
        {name:'BZ',content:'Vue So So'},
      ]
    }
  },
  components:{
    Add,
    List
  },
  methods:{
    /*添加评论,之后将这个方法传递到子文件中*/
    addComments(comment){
      this.comments.unshift(comment);
    },

    /*删除指定下标的评论*/
    deleteComment(index){
      const comment = this.comments[index];
      this.comments.splice(index,1);
      confirm_report.report({
        title: `你成功的删除了"${comment.name}"的评论`,
          text: '单击“收到”以查看详情默认text',
        timeout: 'keep',
        buttons: [{
        text: '收到',
        click: function (e) {
          naranja().success({
            title: '通知',
            text: '通知被接受'
          })
        }
      },{
        text: '取消',
        click: function (e) {
          e.closeNotification()
        }
      }],
        reportType:{
        success:true,
          error:false,
          warm:false,
          log:false
      }
      })
    }
  }
}
</script>
<style scoped>

</style>
